package com.example.rabbitmq.limit;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author： ygl
 * @date： 2019/06/15
 * @Description：
 */
public class MyProducer {

    public static void main(String[] args) throws Exception {

        // 1.创建ConnectionFactory
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");
        // 2.通过链接工厂创建链接
        Connection connection = connectionFactory.newConnection();
        // 3.通过connection创建channel信道
        Channel channel = connection.createChannel();
        // 4.通过channel发送数据
        String exchangeName = "test_qos_exchange";
        String routingKey = "qos.save";
        for (int i = 0; i < 5; i++) {
            String msg = "hello rabbitmq" + i;
            channel.basicPublish(exchangeName, routingKey, null, msg.getBytes());
        }
        // 5.关闭链接
        channel.close();
        connection.close();
    }
}
